package site.marqstree.latte.ec.main.sort.content;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import site.marqstree.latte.core.app.Latte;
import site.marqstree.latte.ec.R;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.latte.ec.main.sort.content
 * 文件名: ItemNodeProvider
 * 创建者: marqstree
 * 创建时间: 2020/1/30 9:28
 * 描述: TODO
 */
public class ItemNodeProvider extends BaseNodeProvider {

    //设置图片加载策略
    private static final RequestOptions RECYCLER_OPTIONS =
            new RequestOptions()
                    .centerCrop()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .dontAnimate();

    @Override
    public int getItemViewType() {
        return 1;
    }

    @Override
    public int getLayoutId() {
        return R.layout.section_sort_item_content;
    }

    @Override
    public void convert(BaseViewHolder holder, BaseNode data) {
        if (data == null) {
            return;
        }

        ItemNode entity = (ItemNode) data;
        String imgUrl = entity.getThumb();
        Glide.with(Latte.getApplicationContext())
                .load(imgUrl)
                .apply(RECYCLER_OPTIONS)
                .into((ImageView) holder.getView(R.id.ivThumb));
        holder.setText(R.id.tvName, entity.getName());
    }
}
